package com.cw.DesignModel23.Ceational.PrototypePattern.cloneFramework;

/**
 * 实现类
 */

/**
 * use 方法的作用是将字符串用双引号括起来显示，并在字符串下面加上下划线。例如，当 ulchar 保存的字符为'~' 方法接收到的字符串为Hello时，显示结果如下
 *
 * "Hellor"
 *  ~~~~~~
 */
public class UnderlinePen implements Product {
    private char ulchar;

    public UnderlinePen(char ulchar) {
        this.ulchar = ulchar;
    }

    public void use(String s) {
        int length = s.getBytes().length;
        System.out.println("\"" + s + "\"");
        System.out.print(" ");
        for (int i = 0; i < length; i++) {
            System.out.print(ulchar);
        }
        System.out.println("");
    }

    public Product createClone() {
        Product p = null;
        try {
            p = (Product) clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return p;
    }
}
